//
//  XMLogger.swift
//  zhonglb_iOS
//
//  Created by Rowling on 2021/11/23.
//

import Foundation

struct XMLogger {
    enum LoggerModel : Int {
        case All = 0
        case info = 1
        case tracking = 2
        case warnning = 3
        case error = 4
    }
    
    static let loggerModel = LoggerModel.info
    
    static var enableNetLog = true

    private static func _log<T>(_ title: String, _ msg: T, _ file: NSString,
                               _ fn: String, _ line: Int) {
        #if DEBUG
        print("\(title) \(file.lastPathComponent) >> \(line) >> \(fn) ：\(msg)")
        #endif
    }
    
    private static func _netLog<T>(_ msg: T) {
        #if DEBUG
        print("\(msg)")
        #endif
    }
    
    static func error<T>(_ msg: T,
                         _ file: NSString = #file,
                         _ fn: String = #function,
                         _ line: Int = #line) {
        if loggerModel.rawValue <= LoggerModel.error.rawValue {
            _log("❌", msg, file, fn, line)
        }
    }
    
    static func warnning<T>(_ msg: T,
                         _ file: NSString = #file,
                         _ fn: String = #function,
                         _ line: Int = #line) {
        if loggerModel.rawValue <= LoggerModel.warnning.rawValue {
            _log("⚠️", msg, file, fn, line)
        }
    }
    
    static func tracking<T>(_ msg: T,
                         _ file: NSString = #file,
                         _ fn: String = #function,
                         _ line: Int = #line) {
        if loggerModel.rawValue <= LoggerModel.tracking.rawValue {
            _log("⏩", msg, file, fn, line)
        }
    }
    
    static func info<T>(_ msg: T,
                         _ file: NSString = #file,
                         _ fn: String = #function,
                         _ line: Int = #line) {
        if loggerModel.rawValue <= LoggerModel.info.rawValue {
            _log("✔️", msg, file, fn, line)
        }
    }
    
    static func netInfo<T>(_ msg: T) {
        if enableNetLog {
            _netLog(msg)
        }
    }
}
